package base.application;

import android.app.Application;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
import android.widget.Toast;

/*
 * Design with <Single Instance Mode>
 */

/**
 * Application manager.
 * 
 * @author Administrator
 * 
 */
public class BaseApplication extends Application {

	private static final String TAG = BaseApplication.class.getSimpleName();

	private static BaseApplication mInstance;

	public BaseApplication() {
		mInstance = this;
	}

	@SuppressWarnings("unchecked")
	public static BaseApplication getInstance() {
		return mInstance;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		Log.v(TAG, "onCreate");
	}

	@Override
	public void onLowMemory() {
		super.onLowMemory();
		Log.w(TAG, "onLowMemory");
	}

	public static void showToast(int res) {
		Toast.makeText(BaseApplication.getInstance().getApplicationContext(), res, Toast.LENGTH_SHORT).show();
	}

	public static void showToast(String res) {
		Toast.makeText(BaseApplication.getInstance().getApplicationContext(), res, Toast.LENGTH_SHORT).show();
	}

	/**
	 * 
	 * Description（描述）:<br/> 
	 * Conditions（适用条件）:<br/> 
	 * Execution flow（执行流程）:<br/> 
	 * Usage（用法）:<br/> 
	 * Cautions（注意事项）:<br/> 
	 * 
	 * @author DavidZou
	 * @param vCodeShowable	显示小版本号
	 * @return
	 */
	public static String getVersion(boolean vCodeShowable) {
		String version = "";
		try {
			PackageInfo pi = getInstance().getPackageManager().getPackageInfo(getInstance().getPackageName(), 0);
			version = pi.versionName + ( vCodeShowable ? ("." + pi.versionCode) : "");
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return version;
	}

}
